<?php


namespace app\blog\controller;


use app\model\CmsMenu;

class Detail extends Base
{
    public function index ($id) {
        $dataArr = []; // 本页数据集合
        /**
         *   获取栏目列表 默认查不隐藏的
         * @param
         * @date 2019/12/2
         * @author Xiaohui Zeng
         */
        $CmsMenuArr = new menu();
        $CmsMenuList = $CmsMenuArr->index();
        $dataArr['CmsMenuList'] = $CmsMenuList;
        /**
         *   获取详情
         *   @param id
         *   @date 2019/12/3
         *   @author Xiaohui Zeng
         */
        $detail = new Content();
        $detailData = $detail->detail($id);
        // 如果id文章页面存在
        $classId = $detailData['classid'];
        $dataArr['CmsDetail'] = $detailData;

        /**
         *   用于获取输出页面信息 标题 关键字 描述信息
         * @param
         * @date 2019/12/1
         * @author Xiaohui Zeng
         */
        $pageInfo{"id"} = $classId;
        $menuDdata = CmsMenu::get($classId); // 通过id获取fid
        $pageInfo{"fid"} = $menuDdata['fid'];
        $pageInfo{"name"} = $detailData['title'];
        $pageInfo{"keywords"} = $detailData['keyboard'];
        $pageInfo{"info"} = $detailData['easytitle'];
        $this->assign('pageInfo', $pageInfo);
        /**
         *   获取随机文章
         *   @param $num 默认4
         *   @date 2019/12/3
         *   @author Xiaohui Zeng
         */
        $randomData = $detail->getRandom(4);
        $dataArr['CmsRandomData'] = $randomData;

        $this->assign('dataArr', $dataArr); // 统一输出数据 json字符串输出到模板
//        return $this->buildSuccess(['list' => $detailData], '获取成功'); // 返回json 用于调试
        return $this->fetch('/detail/detail');
    }
}